package tn.redmine.pages;

import org.openqa.selenium.By;

import tn.redmine.data_models.User;
import core.Pilot;
import core.base.PageBase;

/**
 * Class provides access to web elements and actions on Index page
 */
public class HomePage extends PageBase
{
	private static Pilot pilot = new Pilot();
	// Projects form
	public static By selectProjects = By.id("project_quick_jump_box");
	// Project menu
	public static By blockMainMenu = By.id("main-menu");
	// Side bar
	public static By linkReports = By.xpath("(//div[@id='sidebar']//a)[3]");

	public HomePage(Pilot p_manager)
	{
		super(p_manager);
	}

	public void selectProjects(String p_projectName)
	{
		pilot.driver().selectByText(selectProjects, p_projectName);
		pilot.driver().waitForVisibility(blockMainMenu, "", true);
	}

	public void openReportsPage()
	{
		pilot.driver().click(linkReports);
		pilot.driver().waitForVisibility(ReportsPage.formQuery, "", true);
	}

	public static void openReports(User p_user, String p_period)// String p_project, String p_period, String
																// p_memberShortName)
	{
		String url = pilot.dashboard().getSiteUrl();

		url += "/projects/"
				+ p_user.getRedmineProject()
				+ "/time_entries/report?utf8=%E2%9C%93&criteria[]=user&criteria[]=activity&f[]=spent_on&op[spent_on]=" + p_period
				+ "&f[]=user_id&op[user_id]=%3D&v[user_id][]=" + p_user.getRedmineID() + "&f[]=&columns=month&criteria[]=issue";

		pilot.driver().openURL(url);
		pilot.driver().waitForVisibility(ReportsPage.blockTimeReport, "", true);
	}

	public static void openReportsDetailed(User p_user, String p_period)// String p_project, String p_period, String
																		// p_memberShortName)
	{
		String url = pilot.dashboard().getSiteUrl();

		url += "/projects/"
				+ p_user.getRedmineProject()
				+ "/time_entries?per_page=500&f[]=spent_on&op[spent_on]=" + p_period
				+ "&f[]=user_id&op[user_id]=%3D&v[user_id][]=" + p_user.getRedmineID()
				+ "&f[]=&c[]=spent_on&c[]=user&c[]=activity&c[]=project&c[]=issue&c[]=comments&c[]=hours&sort=spent_on";

		pilot.driver().openURL(url);
		pilot.driver().waitForVisibility(ReportsPage.blockDetailedTimeReport, "", true);
	}
}